<template>
  <div class="container" v-show="visible">
    <!-- 遮罩层 -->
    <div class="mask" @click="closeMask"></div>
    <!-- 弹框 -->
    <div class="dialog" :style="{ width: width }">
      <div class="header">
        <slot name="header"></slot>
        <button class="btn">
          <i class="close" @click="closeDialog">X</i>
        </button>
      </div>
      <div class="body">
        <slot name="body"></slot>
      </div>
      <div class="footer">
        <slot name="footer"></slot>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "MyDialog",
  props: {
    width: {
      type: String,
      default: "50%",
    },
    visible: {
      type: Boolean,
      default: true,
    },
  },
  mounted() {},
  methods: {
    closeMask() {
      this.$emit("closeMask");
    },
    closeDialog() {
      this.$emit("closeDialog", !this.visible);
    },
  },
};
</script>

<style scoped lang="scss">
.container {
  .mask {
    top: 0;
    left: 0;
    position: fixed;
    width: 100%;
    height: 100%;
    background-color: black;
    opacity: 0.6;
    animation: mask1 1s linear forwards;
  }
  .dialog {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    height: 300px;
    background-color: white;
    animation: dialog1 0.5s linear forwards;
    .btn {
      position: absolute;
      top: 5px;
      right: 5px;
    }
    .footer {
      position: absolute;
      bottom: 15px;
      right: 15px;
    }
  }
}
</style>
